package com.hllxd.hism.star.basic.service.service;


import com.hllxd.hism.star.basic.service.dao.http.RockAssemApiMapper;
import com.hllxd.hism.star.basic.service.dao.mapper.mis.HdfsTableMapper;
import com.hllxd.hism.star.basic.service.model.rock.HdfsTableDeleteEntity;
import com.hllxd.hism.star.basic.service.model.rock.HdfsTableEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 跳房子订单实现类
 *
 * @author lixiyong
 * @date 2020/12/20 16:15
 */
@Slf4j
@Service("hdfsTableService")
public class HdfsTableServiceImpl implements HdfsTableService {

    @Autowired
    HdfsTableMapper yarnApplicationMapper;

    @Autowired
    RockAssemApiMapper rockAssemApiMapper;

    @Override
    public List<HdfsTableEntity> listHdfsTable(String clusterName) {
        return yarnApplicationMapper.listHdfsTable(clusterName);
    }

    @Override
    public HdfsTableEntity getHdfsTable(Long id) {
        return yarnApplicationMapper.getHdfsTable(id);
    }

    @Override public Boolean deleteHdfsTable(String clusterName, String queue, String accessID, String appid) {
        // 记录对应的操作
        HdfsTableDeleteEntity entity = HdfsTableDeleteEntity.build(clusterName, queue, accessID, appid, "DELETE-ING");
        yarnApplicationMapper.insertHdfsTableDelete(entity);

        Boolean ret = rockAssemApiMapper.yarnKillApp(clusterName, appid, accessID);
        if(ret) {
            log.info("kill success. {}, {}, {}", clusterName, appid, accessID);
            yarnApplicationMapper.updateHdfsTableDeleteStatus(appid, "DELETE-SUCCESS");
        }else {
            log.info("kill failed. {}, {}, {}", clusterName, appid, accessID);
            yarnApplicationMapper.updateHdfsTableDeleteStatus(appid, "DELETE-FAILED");
        }

        return true;
    }
}
